/*
 * Copyright (C) 2015 soud
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef TOKEN_H
#define TOKEN_H

typedef enum {
        TOKEN_PLUS,
        TOKEN_PLUS_EQ,
        TOKEN_MIN,
        TOKEN_MIN_EQ,
        TOKEN_B_OR,
        TOKEN_B_OR_EQ,
        TOKEN_B_XOR,
        TOKEN_B_XOR_EQ,
        TOKEN_B_AND,
        TOKEN_B_AND_EQ,
        TOKEN_B_NOT,
        TOKEN_B_NOT_EQ,
        TOKEN_L_SHIFT,
        TOKEN_R_SHIFT,
        TOKEN_AND,
        TOKEN_OR,
        TOKEN_SLASH,
        TOKEN_SLASH_EQ,
        TOKEN_STAR,
        TOKEN_STAR_EQ,
        TOKEN_STAR_STAR,
        TOKEN_MOD,
        TOKEN_MOD_EQ,
        TOKEN_AMP,
        TOKEN_BANG,
        TOKEN_LT,
        TOKEN_GT,
        TOKEN_LT_EQ,
        TOKEN_GT_EQ,
        TOKEN_EQ,
        TOKEN_EQ_EQ,
        TOKEN_NOT_EQ,

        TOKEN_L_PAREN,
        TOKEN_R_PAREN,
        TOKEN_L_BRACKET,
        TOKEN_R_BRACKET,
        TOKEN_L_BRACE,
        TOKEN_R_BRACE,
        TOKEN_DOT,
        TOKEN_SEMI_COLON,
        TOKEN_COLON,
        TOKEN_NS_SEP,
        TOKEN_R_ARROW,
        TOKEN_COMMA,

        TOKEN_NUMBER,
        TOKEN_STRING,
        TOKEN_CHAR,

        TOKEN_TRUE,
        TOKEN_FALSE,
        TOKEN_IDENT,
        TOKEN_FUNCTION,
        TOKEN_MUTABLE,
        TOKEN_IF,
        TOKEN_UNLESS,
        TOKEN_ELSE,
        TOKEN_IMPORT,
        TOKEN_RETURN,
        TOKEN_FOR,
        TOKEN_WHILE,
        TOKEN_BREAK,
        TOKEN_CONTINUE,

        TOKEN_ERROR,
        TOKEN_EOF,

        TOKEN_COUNT
} tokentype;

typedef struct token {
        tokentype type;

        char *value;
        size_t line_n;

        size_t start;
        size_t end;

        struct token *prev;
        struct token *next;
} token_t;

#define NULL_TOKEN (token_t) { TOKEN_ERROR, NULL, NULL, NULL, NULL, NULL, NULL }

token_t *new_token(tokentype type, char *value, size_t start, size_t end, size_t line_n);
char *token_value(const char *source, size_t start, size_t end);
void dump_tokens(token_t *token);
void destroy_tokens(token_t *ts);

#endif /* !TOKEN_H */
